package com.koron.css2.serviceManage.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.AdminAreaBean;
import com.koron.css2.serviceManage.bean.AdminAreaListBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.PubAdminAreaMapper;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.List;

public class AdminAreaQuery implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PageInfo.class);
		 try {
			 	AdminAreaBean bean = JsonUtils.objectToPojo(req.getData(), AdminAreaBean.class);
	            PubAdminAreaMapper mapper = factory.getMapper(PubAdminAreaMapper.class,"_default");
	            List<AdminAreaListBean> list=new ArrayList<AdminAreaListBean>();
	            
	           // TWaterCompanyMapper twmapper = factory.getMapper(TWaterCompanyMapper.class,"_default");
				//获取水司设置的code
				//String adminAreaDivi = twmapper.selectCompanyByCode(userInfo.getCurWaterCode());
				bean.setGroup(userInfo.getCurWaterCode());
	            //如果是集抄端登陆则需要根据水司编号进行查询
	            PageHelper.startPage(1, 10);//模糊查询固定查10个
	            list = mapper.queryListByName(bean);
	            info.setData(new PageInfo<>(list));
	        } catch (Exception e) {
	            info.setCode(Constant.MESSAGE_INT_FAIL);
	            info.setDescription(e.getMessage());
	            logger.error(e.getMessage(), e);
	        }
	        return info;
	}

}
